package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantcertService;
import com.youi.entity.Merchantcert;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 商家证件信息控制层
* @author Administrator
*/
@Controller
public class MerchantcertController  extends HttpRequestManage{

		@Autowired
		private MerchantcertService merchantcertService;

		/**
		 * I-81
		 * 添加或编辑商家证件信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantcert")
		public String addOrEditMerchantcert(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);	
			Merchantcert merchantcert=merchantcertService.getByParam(prams);
			if (merchantcert==null) {
				merchantcert=new Merchantcert();
				merchantcert.setDelStatus(DelStatus.NODEL);
				merchantcert.setGmtCreated(new Date());
				merchantcert.setMerchantId(id);
			}
			String openaccountCert=optString("openaccountCert",request);
			if (openaccountCert!=null){
				merchantcert.setOpenaccountCert(openaccountCert);
			}
			String taxCertificate=optString("taxCertificate",request);
			if (taxCertificate!=null){
				merchantcert.setTaxCertificate(taxCertificate);
			}
			String idCardFront=optString("idCardFront",request);
			if (idCardFront!=null){
				merchantcert.setIdCardFront(idCardFront);
			}
			String idCareBehind=optString("idCareBehind",request);
			if (idCareBehind!=null){
				merchantcert.setIdCareBehind(idCareBehind);
			}
			String handInCard=optString("handInCard",request);
			if (handInCard!=null){
				merchantcert.setHandInCard(handInCard);
			}
			String usicCert=optString("usicCert",request);
			if (usicCert!=null){
				merchantcert.setUsicCert(usicCert);
			}
			merchantcert.setGmtModify(new Date());
			merchantcertService.saveOrUpdate(merchantcert);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}
		

		/**
		 * I-82
		 * 查询商家证件信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantcertById")
		public String getMerchantcertById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);	
			Merchantcert merchantcert=merchantcertService.getByParam(prams);
			if (merchantcert==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantcert);//jsonObject	json对象
		}

		
}
